const fs = require("fs");
let data = require("./data.json");

let head = `
# project
## 配置表
| 名字           | 意义 | 类型 | 默认值 |
| -------------- | ---- | ---- | ------ |`;

data.sort(function (a, b) {
  if (a.nameValue < b.nameValue) {
    return -1;
  } else {
    return 1;
  }
});
let lines = [head];
data.map((item) => {
  lines.push(getRecord(item));
});
let result = lines.join("\n");

let 示例 = `



## 示例

\`\`\`js
{
  "androidResources": {
    "resDir": "res",
    "manifest": "AndroidManifest.xml"
  },
  "assets": [],
  "build": {
    "build_id": "6F47F367-1",
    "build_number": 1,
    "build_time": 1615553004812,
    "release": true
  },
  "encryptLevel": 0,
  "useFeatures": [],
  "icon": "res/icon.png",
  "ignore": ["build"],
  "launchConfig": {
    "displaySplash": true,
    "hideLogs": false,
    "splashIcon": "res/splashIcon.png",
    "splashText": "Powered by Auto.js Pro",
    "stableMode": false
  },
  "main": "main.js",
  "name": "Shape3.0",
  "optimization": {
    "removeOpenCv": true,
    "unusedResources": true
  },
  "packageName": "com.suzy.rippledrawable",
  "publish": {
    "category": "其他",
    "details": "控件描边、渐变、水波纹、文字渐变",
    "maxAutoJsVersion": -1,
    "minAutoJsVersion": -1,
    "maxProVersion": 8059999,
    "minProVersion": 8050000,
    "minSdkVersion": 2,
    "permissions": [],
    "summary": "控件描边、渐变、水波纹、文字渐变",
    "tags": []
  },
  "scripts": {},
  "versionCode": 1,
  "versionName": "1.0.0"
}
\`\`\`

`;
result += 示例;

console.log(result);
fs.writeFileSync("projectJson.md", result, "utf8");
// getRecord(item)

function getRecord(item) {
  if (toRawType(item.defaultValue) === "String") {
    item.defaultValue = item.defaultValue.replace(/\n/g, "<br>");
  }
  let body = `| ${item.nameValue} | ${item.meaningValue} | ${item.typeValue} | ${item.defaultValue} |`;
  return body;
}

function toRawType(value) {
  return Object.prototype.toString.call(value).slice(8, -1);
}
